//
//  DQCommendController.m
//  DQBaisibudejie
//
//  Created by 杜倩 on 16/9/5.
//  Copyright © 2016年 杜倩. All rights reserved.
//

#import "DQCommendController.h"
#import "DQFirstController.h"
#import "DQSecondController.h"
@interface DQCommendController ()

@end

@implementation DQCommendController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title=@"推荐关注";
    
    //定义两个控制器
    DQFirstController *first=[[DQFirstController alloc] init];
    //定义第一个控制器的大小
    CGFloat width= self.view.frame.size.width*(1.0/5);
    CGFloat height=self.view.frame.size.height;
    first.view.frame=CGRectMake(0, 0, width, height);
    
    DQSecondController *second=[[DQSecondController alloc] init];
    //第二个的大小
    second.view.frame=CGRectMake(width, 0, width*4, height);
    
    first.delegate=second;//设置代理
    
    [self.view addSubview:first.view];
    //加载控制器--如不加载控制器，有可能导致不能处理事件
    [self addChildViewController:first];
    
    [self.view addSubview:second.view];
    [self addChildViewController:second];
    [self addBackLeft];
}
#pragma mark 左边的返回键
-(void)addBackLeft{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    //设置标题
    [button setTitle:@"返回" forState:UIControlStateNormal];
    //设置按钮内边距
    button.contentEdgeInsets=UIEdgeInsetsMake(0, -15, 0, 0);//返回按钮箭头距离边缘的大小

    [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];//高亮状态
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];//正常状态下的
    
    [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
    UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithCustomView:button];
    [button sizeToFit];//自动适应大小
    [button addTarget:self action:@selector(goToBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationController.interactivePopGestureRecognizer.delegate = nil;//清空手势，实现拖拽
    self.navigationItem.leftBarButtonItem=item;


}
#pragma Mark 返回按钮的单击事件
-(void)goToBack{
    self.tabBarController.tabBar.hidden=NO;//返回显示标签栏
    [self.navigationController popToRootViewControllerAnimated:YES];//返回上一级控制器
}

@end
